package com.wyg.ep_timer.config.kafka;

import com.wyg.epcommonbase.common.util.StringUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: WangYongGan
 * @Date: 2022/5/17 2:10
 * @Description:
 */
@Component
public class MailTopic implements InitializingBean {
    static String mailTopic = "ep_mail";
    //    @Autowired
    KafkaTemplate<String, Object> kafkaTemplate_;
    static KafkaTemplate<String, Object> kafkaTemplate;

    @Override
    public void afterPropertiesSet() throws Exception {
        kafkaTemplate = kafkaTemplate_;
    }

    public static void sendMailKafka(String to, List<String> entities) {
        String msg = to + ":::" + StringUtil.trimList(entities);
        kafkaTemplate.send(mailTopic, msg);
    }

    public static void sendMailKafka(String msg) {
        kafkaTemplate.send(mailTopic, msg);
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>(Arrays.asList("aaa", "bbb", "ccc"));
        System.out.println(StringUtil.trimList(list));
    }
}
